home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 1.toast / Sample Code / Devices and Hardware / Drivers / TradDriverLoaderLib / MissingLibraryRoutines.c next >
Encoding:
C/C++ Source or Header  |  2000-09-28  |  3.6 KB  |  94 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        MissingLibraryRoutines.c
  3.     
  4.     Description:Implementation of routines missing from InterfaceLib.
  5.  
  6.     Author:        Quinn
  7.  
  8.     Copyright:     Copyright: © 1997-1999 by Apple Computer, Inc.
  9.                 all rights reserved.
  10.     
  11.     Disclaimer:    You may incorporate this sample code into your applications without
  12.                 restriction, though the sample code has been provided "AS IS" and the
  13.                 responsibility for its operation is 100% yours.  However, what you are
  14.                 not permitted to do is to redistribute the source as "DSC Sample Code"
  15.                 after having made changes. If you're going to re-distribute the source,
  16.                 we require that you make it clear in the source that the code was
  17.                 descended from Apple Sample Code, but that you've made changes.
  18.     
  19.     Change History (most recent first):
  20.                 6/24/99    Updated for Metrowerks Codewarror Pro 2.1(KG)
  21.  
  22. */
  23. #include <Types.h>
  24.  
  25. // This file contains implementations of various Mac OS API routines
  26. // that were never rolled in to InterfaceLib.  As a result, these
  27. // routines can be called from classic 68K clients, but not from
  28. // CFM-68K or CFM-PPC clients.
  29.  
  30. extern pascal SInt16 LMGetUnitTableEntryCount(void)
  31.     // Get the value from low memory directly.
  32. {
  33.     return *((SInt16 *) 0x01d2);
  34. }
  35.  
  36. extern pascal void LMSetUnitTableEntryCount(SInt16 value)
  37.     // Put the value into low memory directly.
  38. {
  39.     *((SInt16 *) 0x01d2) = value;
  40. }
  41.  
  42. // DriverInstallReserveMem is a bit trickier to implement that the
  43. // previous two routines.  Basically we have get the address of the
  44. // _DriverInstall ($A03D) trap and then call it using
  45. // CallOSTrapUniversalProc.  There are a number of important things
  46. // to note here:
  47. //   a) We can just get the trap address and treat it as a UPP.
  48. //      The trap tables are defined to contain UPPs, either pointers
  49. //      to real 68K code, or pointers to a routine descriptor (if
  50. //      the trap is native or fat).
  51. //   b) We must use CallOSTrapUniversalProc, not CallUniversalProc.
  52. //      CallOSTrapUniversalProc automatically does a number of things 
  53. //      that are very critical for call OS traps.  See "IM:PowerPC
  54. //      System Software", p2-42 for a full description.
  55. //   c) When calling OS traps from PPC, it's important to get the
  56. //      ProcInfo right.  Specifically, all OS traps assume an
  57. //      implicit parameter of D1 as the first parameter.  After
  58. //      that, the parameters should be defined in the order that
  59. //      they are declared in the prototype.  If you fail to get
  60. //      the order right, or to put D1 first, your code will work,
  61. //      up until it encounters someone who has patched the OS trap
  62. //      with a native or fat patch.  Then strange things will happen,
  63. //      and you'll spend hours in MacsBug trying to figure it out.
  64.  
  65. // The trap number and ProcInfo description for DriverInstallReserveMem.
  66.  
  67. enum {
  68.     _DriverInstallReserveMem = 0x0A43D
  69. };
  70.  
  71. enum {
  72.     uppDriverInstallProcInfo = kRegisterBased
  73.         | REGISTER_RESULT_LOCATION(kRegisterD0)
  74.         | RESULT_SIZE(SIZE_CODE(sizeof(OSErr)))
  75.         | REGISTER_ROUTINE_PARAMETER(1, kRegisterD1, SIZE_CODE(sizeof(short)))
  76.         | REGISTER_ROUTINE_PARAMETER(2, kRegisterA0, SIZE_CODE(sizeof(DRVRHeaderPtr)))
  77.         | REGISTER_ROUTINE_PARAMETER(3, kRegisterD0, SIZE_CODE(sizeof(short)))
  78. };
  79.  
  80. extern pascal OSErr DriverInstallReserveMem(DRVRHeaderPtr drvrPtr, short refNum)
  81. {
  82.     UniversalProcPtr trapAddress;
  83.     
  84.     // Check that I've got the ProcInfo correct.
  85.     if (false) {
  86.         if ( uppDriverInstallProcInfo != 0x00533022) {
  87.             DebugStr("\pDriverInstallReserveMem: uppDriverInstallProcInfo is not what it should be.");
  88.         }
  89.     }
  90.     
  91.     trapAddress = (UniversalProcPtr) GetOSTrapAddress(_DriverInstallReserveMem);
  92.     return CallOSTrapUniversalProc(trapAddress, uppDriverInstallProcInfo, _DriverInstallReserveMem, drvrPtr, refNum);
  93. }
  94.